package com.web.dao;

import com.web.entity.Version;
import com.web.entity.VersionExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface VersionMapper {
    @SelectProvider(type=VersionSqlProvider.class, method="countByExample")
    int countByExample(VersionExample example);

    @DeleteProvider(type=VersionSqlProvider.class, method="deleteByExample")
    int deleteByExample(VersionExample example);

    @Delete({
        "delete from t_version",
        " where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into t_version (min_version, max_version, ",
        " platform, down_load_url, ",
        " description, create_time, ",
        " modify_time)",
        " values (#{minVersion,jdbcType=VARCHAR}, #{maxVersion,jdbcType=VARCHAR}, ",
        " #{platform,jdbcType=VARCHAR}, #{downLoadUrl,jdbcType=VARCHAR}, ",
        " #{description,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
        " #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(Version record);

    @InsertProvider(type=VersionSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insertSelective(Version record);

    @SelectProvider(type=VersionSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="min_version", property="minVersion", jdbcType=JdbcType.VARCHAR),
        @Result(column="max_version", property="maxVersion", jdbcType=JdbcType.VARCHAR),
        @Result(column="platform", property="platform", jdbcType=JdbcType.VARCHAR),
        @Result(column="down_load_url", property="downLoadUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Version> selectByExample(VersionExample example);

    @Select({
        "select",
        " id, min_version, max_version, platform, down_load_url, description, create_time, ",
        " modify_time",
        " from t_version",
        " where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="min_version", property="minVersion", jdbcType=JdbcType.VARCHAR),
        @Result(column="max_version", property="maxVersion", jdbcType=JdbcType.VARCHAR),
        @Result(column="platform", property="platform", jdbcType=JdbcType.VARCHAR),
        @Result(column="down_load_url", property="downLoadUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Version selectByPrimaryKey(Integer id);

    @UpdateProvider(type=VersionSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Version record, @Param("example") VersionExample example);

    @UpdateProvider(type=VersionSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Version record, @Param("example") VersionExample example);

    @UpdateProvider(type=VersionSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Version record);

    @Update({
        "update t_version",
        " set min_version = #{minVersion,jdbcType=VARCHAR},",
          " max_version = #{maxVersion,jdbcType=VARCHAR},",
          " platform = #{platform,jdbcType=VARCHAR},",
          " down_load_url = #{downLoadUrl,jdbcType=VARCHAR},",
          " description = #{description,jdbcType=VARCHAR},",
          " create_time = #{createTime,jdbcType=TIMESTAMP},",
          " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        " where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Version record);

    @Select({
            "select",
            " id, min_version, max_version, platform, down_load_url, description, create_time, ",
            " modify_time",
            " from t_version",
            " where platform = #{platform,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="min_version", property="minVersion", jdbcType=JdbcType.VARCHAR),
            @Result(column="max_version", property="maxVersion", jdbcType=JdbcType.VARCHAR),
            @Result(column="platform", property="platform", jdbcType=JdbcType.VARCHAR),
            @Result(column="down_load_url", property="downLoadUrl", jdbcType=JdbcType.VARCHAR),
            @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Version findByPlatform(String platform);
}